package com.wx.mythread.threadmethod;


/**
 * 演示join期间线程被中断的效果
 */
public class StudyJoinInterrupt {


    public static void main(String[] args) {
        Thread mainThread = Thread.currentThread();
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(5000);
                    System.out.println(Thread.currentThread().getName() + "线程执行完毕");
                } catch (InterruptedException e) {
                    System.out.println("子线程发送中断");
                    // e.printStackTrace();
                }
            }
        });

        thread.start();
        System.out.println("等待子线程执行完毕");
        try {
            mainThread.interrupt();
            thread.join();
        } catch (InterruptedException e) {
            System.out.println(Thread.currentThread().getName() + "发送中断");
            thread.interrupt();
            // e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + "所有线程运行完毕");

    }
}
